home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / findfile / wsksock.bas < prev   
BASIC Source File  |  1999-04-25  |  37KB  |  862 lines

  1. Attribute VB_Name = "WSKSOCK"
  2. 'date stamp: sept 1, 1996 (for version control, please don't remove)
  3.  
  4. 'Visual Basic 4.0 Winsock "Header"
  5. '   Alot of the information contained inside this file was originally
  6. '   obtained from ALT.WINSOCK.PROGRAMMING and most of it has since been
  7. '   modified in some way.
  8. '
  9. 'Disclaimer: This file is public domain, updated periodically by
  10. '   Topaz, SigSegV@mail.utexas.edu, Use it at your own risk.
  11. '   Neither myself(Topaz) or anyone related to alt.programming.winsock
  12. '   may be held liable for its use, or misuse.
  13. '
  14. 'Declare check Aug 27, 1996. (Topaz, SigSegV@mail.utexas.edu)
  15. '   All 16 bit declarations appear correct, even the odd ones that
  16. '   pass longs inplace of in_addr and char buffers. 32 bit functions
  17. '   also appear correct. Some are declared to return integers instead of
  18. '   longs (breaking MS's rules.) however after testing these functions I
  19. '   have come to the conclusion that they do not work properly when declared
  20. '   following MS's rules.
  21. '
  22. 'NOTES:
  23. '   (1) I have never used WS_SELECT (select), therefore I must warn that I do
  24. '       not know if fd_set and timeval are properly defined.
  25. '   (2) Alot of the functions are declared with "buf as any", when calling these
  26. '       functions you may either pass strings, byte arrays or UDT's. For 32bit I
  27. '       I recommend Byte arrays and the use of memcopy to copy the data back out
  28. '   (3) The async functions (wsaAsync*) require the use of a message hook or
  29. '       message window control to capture messages sent by the winsock stack. This
  30. '       is not to be confused with a CallBack control, The only function that uses
  31. '       callbacks is WSASetBlockingHook()
  32. '   (4) Alot of "helper" functions are provided in the file for various things
  33. '       before attempting to figure out how to call a function, look and see if
  34. '       there is already a helper function for it.
  35. '   (5) Data types (hostent etc) have kept there 16bit definitions, even under 32bit
  36. '       windows due to the problem of them not working when redfined following the
  37. '       suggested rules.
  38. Option Explicit
  39.  
  40. Public Const FD_SETSIZE = 64
  41. Type fd_set
  42.     fd_count As Integer
  43.     fd_array(FD_SETSIZE) As Integer
  44. End Type
  45.  
  46. Type timeval
  47.     tv_sec As Long
  48.     tv_usec As Long
  49. End Type
  50.  
  51. Type HostEnt
  52.     h_name As Long
  53.     h_aliases As Long
  54.     h_addrtype As Integer
  55.     h_length As Integer
  56.     h_addr_list As Long
  57. End Type
  58. Public Const hostent_size = 16
  59.  
  60. Type servent
  61.     s_name As Long
  62.     s_aliases As Long
  63.     s_port As Integer
  64.     s_proto As Long
  65. End Type
  66. Public Const servent_size = 14
  67.  
  68. Type protoent
  69.     p_name As Long
  70.     p_aliases As Long
  71.     p_proto As Integer
  72. End Type
  73. Public Const protoent_size = 10
  74.  
  75. Public Const IPPROTO_TCP = 6
  76. Public Const IPPROTO_UDP = 17
  77.  
  78. Public Const INADDR_NONE = &HFFFFFFFF
  79. Public Const INADDR_ANY = &H0
  80.  
  81. Type sockaddr
  82.     sin_family As Integer
  83.     sin_port As Integer
  84.     sin_addr As Long
  85.     sin_zero As String * 8
  86. End Type
  87. Public Const sockaddr_size = 16
  88. Public saZero As sockaddr
  89.  
  90.  
  91. Public Const WSA_DESCRIPTIONLEN = 256
  92. Public Const WSA_DescriptionSize = WSA_DESCRIPTIONLEN + 1
  93.  
  94. Public Const WSA_SYS_STATUS_LEN = 128
  95. Public Const WSA_SysStatusSize = WSA_SYS_STATUS_LEN + 1
  96.  
  97. Type WSADataType
  98.     wVersion As Integer
  99.     wHighVersion As Integer
  100.     szDescription As String * WSA_DescriptionSize
  101.     szSystemStatus As String * WSA_SysStatusSize
  102.     iMaxSockets As Integer
  103.     iMaxUdpDg As Integer
  104.     lpVendorInfo As Long
  105. End Type
  106.  
  107. Public Const INVALID_SOCKET = -1
  108. Public Const SOCKET_ERROR = -1
  109.  
  110. Public Const SOCK_STREAM = 1
  111. Public Const SOCK_DGRAM = 2
  112.  
  113. Public Const MAXGETHOSTSTRUCT = 1024
  114.  
  115. Public Const AF_INET = 2
  116. Public Const PF_INET = 2
  117.  
  118. Type LingerType
  119.     l_onoff As Integer
  120.     l_linger As Integer
  121. End Type
  122. ' Windows Sockets definitions of regular Microsoft C error constants
  123. Global Const WSAEINTR = 10004
  124. Global Const WSAEBADF = 10009
  125. Global Const WSAEACCES = 10013
  126. Global Const WSAEFAULT = 10014
  127. Global Const WSAEINVAL = 10022
  128. Global Const WSAEMFILE = 10024
  129. ' Windows Sockets definitions of regular Berkeley error constants
  130. Global Const WSAEWOULDBLOCK = 10035
  131. Global Const WSAEINPROGRESS = 10036
  132. Global Const WSAEALREADY = 10037
  133. Global Const WSAENOTSOCK = 10038
  134. Global Const WSAEDESTADDRREQ = 10039
  135. Global Const WSAEMSGSIZE = 10040
  136. Global Const WSAEPROTOTYPE = 10041
  137. Global Const WSAENOPROTOOPT = 10042
  138. Global Const WSAEPROTONOSUPPORT = 10043
  139. Global Const WSAESOCKTNOSUPPORT = 10044
  140. Global Const WSAEOPNOTSUPP = 10045
  141. Global Const WSAEPFNOSUPPORT = 10046
  142. Global Const WSAEAFNOSUPPORT = 10047
  143. Global Const WSAEADDRINUSE = 10048
  144. Global Const WSAEADDRNOTAVAIL = 10049
  145. Global Const WSAENETDOWN = 10050
  146. Global Const WSAENETUNREACH = 10051
  147. Global Const WSAENETRESET = 10052
  148. Global Const WSAECONNABORTED = 10053
  149. Global Const WSAECONNRESET = 10054
  150. Global Const WSAENOBUFS = 10055
  151. Global Const WSAEISCONN = 10056
  152. Global Const WSAENOTCONN = 10057
  153. Global Const WSAESHUTDOWN = 10058
  154. Global Const WSAETOOMANYREFS = 10059
  155. Global Const WSAETIMEDOUT = 10060
  156. Global Const WSAECONNREFUSED = 10061
  157. Global Const WSAELOOP = 10062
  158. Global Const WSAENAMETOOLONG = 10063
  159. Global Const WSAEHOSTDOWN = 10064
  160. Global Const WSAEHOSTUNREACH = 10065
  161. Global Const WSAENOTEMPTY = 10066
  162. Global Const WSAEPROCLIM = 10067
  163. Global Const WSAEUSERS = 10068
  164. Global Const WSAEDQUOT = 10069
  165. Global Const WSAESTALE = 10070
  166. Global Const WSAEREMOTE = 10071
  167. ' Extended Windows Sockets error constant definitions
  168. Global Const WSASYSNOTREADY = 10091
  169. Global Const WSAVERNOTSUPPORTED = 10092
  170. Global Const WSANOTINITIALISED = 10093
  171. Global Const WSAHOST_NOT_FOUND = 11001
  172. Global Const WSATRY_AGAIN = 11002
  173. Global Const WSANO_RECOVERY = 11003
  174. Global Const WSANO_DATA = 11004
  175. Global Const WSANO_ADDRESS = 11004
  176. '---ioctl Constants
  177.     Public Const FIONREAD = &H8004667F
  178.     Public Const FIONBIO = &H8004667E
  179.     Public Const FIOASYNC = &H8004667D
  180.  
  181. #If Win16 Then
  182. '---Windows System functions
  183.     Public Declare Function PostMessage Lib "User" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Any) As Integer
  184.     Public Declare Sub MemCopy Lib "Kernel" Alias "hmemcpy" (Dest As Any, Src As Any, ByVal cb&)
  185.     Public Declare Function lstrlen Lib "Kernel" (ByVal lpString As Any) As Integer
  186. '---async notification constants
  187.     Public Const SOL_SOCKET = &HFFFF
  188.     Public Const SO_LINGER = &H80
  189.     Public Const FD_READ = &H1
  190.     Public Const FD_WRITE = &H2
  191.     Public Const FD_OOB = &H4
  192.     Public Const FD_ACCEPT = &H8
  193.     Public Const FD_CONNECT = &H10
  194.     Public Const FD_CLOSE = &H20
  195. '---SOCKET FUNCTIONS
  196.     Public Declare Function accept Lib "Winsock.dll" (ByVal s As Integer, addr As sockaddr, addrlen As Integer) As Integer
  197.     Public Declare Function bind Lib "Winsock.dll" (ByVal s As Integer, addr As sockaddr, ByVal namelen As Integer) As Integer
  198.     Public Declare Function closesocket Lib "Winsock.dll" (ByVal s As Integer) As Integer
  199.     Public Declare Function connect Lib "Winsock.dll" (ByVal s As Integer, addr As sockaddr, ByVal namelen As Integer) As Integer
  200.     Public Declare Function ioctlsocket Lib "Winsock.dll" (ByVal s As Integer, ByVal cmd As Long, argp As Long) As Integer
  201.     Public Declare Function getpeername Lib "Winsock.dll" (ByVal s As Integer, sName As sockaddr, namelen As Integer) As Integer
  202.     Public Declare Function getsockname Lib "Winsock.dll" (ByVal s As Integer, sName As sockaddr, namelen As Integer) As Integer
  203.     Public Declare Function getsockopt Lib "Winsock.dll" (ByVal s As Integer, ByVal level As Integer, ByVal optname As Integer, optval As Any, optlen As Integer) As Integer
  204.     Public Declare Function htonl Lib "Winsock.dll" (ByVal hostlong As Long) As Long
  205.     Public Declare Function htons Lib "Winsock.dll" (ByVal hostshort As Integer) As Integer
  206.     Public Declare Function inet_addr Lib "Winsock.dll" (ByVal cp As String) As Long
  207.     Public Declare Function inet_ntoa Lib "Winsock.dll" (ByVal inn As Long) As Long
  208.     Public Declare Function listen Lib "Winsock.dll" (ByVal s As Integer, ByVal backlog As Integer) As Integer
  209.     Public Declare Function ntohl Lib "Winsock.dll" (ByVal netlong As Long) As Long
  210.     Public Declare Function ntohs Lib "Winsock.dll" (ByVal netshort As Integer) As Integer
  211.     Public Declare Fun